const express = require('express');
const path = require('path');
const router = express.Router();


//设计路由:

//显示注册界面：
router.get('/register',(req,res)=>{

    res.sendFile(path.join(__dirname,'../views/register.html'));
});

//处理注册新用户： 
router.get('/doregister',(req,res)=>{

    //接收参数(用户输入的帐号、密码、确认密码)：
    let {usr='',pwd='',pwd2=''} =req.query;

    if(usr=='' || pwd=='' || pwd2==''){
         res.send(`<script>alert('帐号、密码、确认密码都不能为空');location.href='/register';</script>`);
        return ;
    }

    if(pwd!=pwd2){
        res.send(`<script>alert('两次密码不一致');location.href='/register';</script>`);
        return ;
    }

    res.send(`处理注册`);
});


//暴露(导出)router:
module.exports = router;